#include "book.h"

#include <QDate>

Book::Book()
: m_id( INVALID_ID ),
  m_sharedId( INVALID_ID ),
  m_title( INVALID_STR ),
  m_author( INVALID_STR ),
  m_year( INVALID_YEAR ),
  m_description( INVALID_STR ),
  m_price( INVALID_PRICE ),
  m_borrowDate( QDate() ),
  m_wasBorrowed( false )
{
	// Default constructor
}

Book::Book( const ID &id,
            const ID &sharedId,
            const QString &title,
            const QString &author,
            const int &year,
            const QString &description,
            const int &price,
            const bool &wasBorrowed )
: m_id( id ),
  m_sharedId( sharedId ),
  m_title( title ),
  m_author( author ),
  m_year( year ),
  m_description( description ),
  m_price( price ),
  m_borrowDate( QDate() ),
  m_wasBorrowed( wasBorrowed )
{
}

void Book::setId( const ID &id )
{
	m_id = id;
}

void Book::setSharedId( const ID &sharedId )
{
	m_sharedId = sharedId;
}

void Book::setTitle( const QString &title )
{
	m_title = title;
}

void Book::setAuthor( const QString &author )
{
	m_author = author;
}

void Book::setYear( const int &year )
{
	m_year = year;
}

void Book::setDescription( const QString &description )
{
	m_description = description;
}

void Book::setPrice( const int &price )
{
	m_price = price;
}

void Book::setBorrowDate(const QDate &date)
{
	m_borrowDate = date;
}

ID Book::getId() const
{
	return m_id;
}

ID Book::getSharedId() const
{
	return m_sharedId;
}

QString Book::getTitle() const
{
	return m_title;
}

QString Book::getAuthor() const
{
	return m_author;
}

int Book::getYear() const
{
	return m_year;
}

QString Book::getDescription() const
{
	return m_description;
}

int Book::getPrice() const
{
	return m_price;
}

QDate Book::getBorrowDate() const
{
	return m_borrowDate;
}

bool Book::wasBorrowed() const
{
	return m_wasBorrowed;
}

void Book::setWasBorrowed(const bool &value)
{
	m_wasBorrowed = value;
}

void Book::borrowBook()
{
	if( m_borrowDate.isValid() )
	{
		m_borrowDate = QDate::currentDate();
	}

	m_wasBorrowed = true;
}

void Book::returnBook()
{
	m_borrowDate = QDate();
}
